import java.io.File;
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;

/**
 * 排序国际化资源文件xml，根据string中name属性的字母先后进行重新排序
 * Created by heyiyong on 2016/4/24.
 */
public class XmlSorter {
    public static final String fileName = "xml/strings.xml";
    public static final String saveFileName = "sort_strings.xml";
    public static Map<String, String> keyValMap = new TreeMap<>();

    public static void main(String[] args) throws Exception {
        // 1、找到文件源
        URL resource = XmlSorter.class.getResource(fileName);
        File file = new File(resource.getFile());

        // 2、读取文件，加入到treeMap里
        Utils.readXmlWithChild(keyValMap, file);

        // 3、写出文件
        File saveFile = new File(file.getParent(), saveFileName);
        System.out.println("saveFile = " + saveFile);
        Utils.writeXml(keyValMap.entrySet(), saveFile);
    }

}
